<template>
  <div class="region-add">
    <el-form :model="form">
      <el-form-item label="角色名称" :label-width="formLabelWidth" >
        <el-input v-model="form.roleName" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="排序" :label-width="formLabelWidth">
        <el-input type="age" v-model.number="form.sortNumber" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="描述" :label-width="formLabelWidth">
        <el-input type="textarea" v-model="form.roleDesc"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('change-state',false)">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.dialog-footer{
  text-align: center;
}
.el-cascader{
  width: 100%;
}
</style>
<script>
export default {
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      formLabelWidth: '120px',
      form: {
        id: '',
        roleName: '',
        sortNumber: 1,
        roleDesc: ''
      }
    }
  },
  mounted () {
  },
  methods: {
    submit () {
      this.$axios.post('org/role/add', this.form).then(res => {
        if (res.data.code === 200) {
          this.$emit('reload')
          this.$emit('change-state', false)
          this.$message.success(res.data.msg)
        } else {
          this.$message.success(res.data.msg)
        }
      })
    }
  },
  beforeDestroy () {
    this.$off('reload')
    this.$off('change-state')
  }
}
</script>
